<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class breadcrumb {
    var $_trail;

    function breadcrumb() {
      $this->reset();
    }

    function reset() {
      $this->_trail = array();
    }

    function add($title, $link = '') {
      $this->_trail[] = array('title' => $title, 'link' => $link);
    }

    function trail($separator = ' - ') {
      $trail_string = '';

        for ($i = 0, $n = sizeof($this->_trail); $i < $n; $i++) {
            $class = "headerNavigation";
            if ($i == 0) {
                $class = $class.' first';
            } else if (($n > 1) && ($i == $n - 1)) {
                $class = $class.' last';
            }
            $last_class = ($i == $n - 1 ? 'last' : '');
            if (isset($this->_trail[$i]['link']) && tep_not_null($this->_trail[$i]['link'])) {
                $trail_string .= '<a href="' . $this->_trail[$i]['link'] . '" class="'.$class.'">' . $this->_trail[$i]['title'] . '</a>';
            } else {
                $trail_string .= $this->_trail[$i]['title'];
            }

            if (($i + 1) < $n)
                $trail_string .= $separator;
        }

      return $trail_string;
    }
  }
?>
